package wnxy.wn44.shopwn.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wnxy.wn44.shopwn.entity.Perm;
import wnxy.wn44.shopwn.entity.User;
import wnxy.wn44.shopwn.mapper.UserMapper;
import wnxy.wn44.shopwn.service.UserService;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    @Override
    public int saveUser(User user) {
        return userMapper.insert(user);
    }

    @Override
    public boolean deleteById(Integer userid) {
        return userMapper.deleteByPrimaryKey(userid)!=0;
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<User> findByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list = userMapper.selectAll();
        PageInfo<User> userPageInfo = new PageInfo<>(list);
        return userPageInfo;
    }

    @Override
    public List<User> findByCondition(User user) {
        return userMapper.selectByConditon(user);
    }

    @Override
    public List<Perm> findByJointQuery(int parseInt) {
        return userMapper.selectfindJointQuery(parseInt);
    }
}
